import request from '@/utils/request'

// 使用模拟数据响应
const useMockData = false;

// 模拟数据
const mockData = {
  // 标准列表数据
  standardList: [
    {
      id: 1,
      name: '管道焊接质量标准',
      type: '1',
      description: '适用于各类管道焊接工艺的质量控制标准',
      createTime: '2023-09-01 10:00:00'
    },
    {
      id: 2,
      name: '表面处理检验标准',
      type: '2',
      description: '管道设备表面处理质量检验标准',
      createTime: '2023-09-05 14:30:00'
    },
    {
      id: 3,
      name: '管道安装安全规范',
      type: '3',
      description: '管道设备安装过程中的安全操作规范',
      createTime: '2023-09-10 09:15:00'
    },
    {
      id: 4,
      name: '管道弯曲工艺标准',
      type: '4',
      description: '各类管道弯曲成型工艺技术要求',
      createTime: '2023-09-15 16:45:00'
    }
  ],
  // 标准详情数据
  standardDetail: {
    id: 1,
    name: '管道焊接质量标准',
    type: '1',
    description: '适用于各类管道焊接工艺的质量控制标准，包含焊缝外观检查、射线探伤等检验方法和合格标准',
    createTime: '2023-09-01 10:00:00'
  },
  // 标准参数数据
  standardParams: [
    {
      id: 1,
      standardId: 1,
      paramName: '焊缝外观质量',
      paramValue: '无裂纹、夹渣、气孔',
      paramUnit: '',
      required: 'Y'
    },
    {
      id: 2,
      standardId: 1,
      paramName: '焊缝余高',
      paramValue: '≤2.0',
      paramUnit: 'mm',
      required: 'Y'
    },
    {
      id: 3,
      standardId: 1,
      paramName: '射线探伤',
      paramValue: 'II级',
      paramUnit: '',
      required: 'Y'
    }
  ]
};

// 查询标准列表
export function listStandard(query) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      rows: mockData.standardList,
      total: mockData.standardList.length
    });
  }
  
  return request({
    url: '/qep/standard/list',
    method: 'get',
    params: query
  })
}

// 查询标准详细
export function getStandard(id) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      data: mockData.standardDetail
    });
  }
  
  return request({
    url: '/qep/standard/' + id,
    method: 'get'
  })
}

// 新增标准
export function addStandard(data) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      msg: "操作成功"
    });
  }
  
  return request({
    url: '/qep/standard',
    method: 'post',
    data: data
  })
}

// 修改标准
export function updateStandard(data) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      msg: "操作成功"
    });
  }
  
  return request({
    url: '/qep/standard',
    method: 'put',
    data: data
  })
}

// 删除标准
export function delStandard(id) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      msg: "操作成功"
    });
  }
  
  return request({
    url: '/qep/standard/' + id,
    method: 'delete'
  })
}

// 搜索标准列表
export function searchStandard(query) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      data: mockData.standardList
    });
  }
  
  return request({
    url: '/qep/standard/search',
    method: 'get',
    params: query
  })
}

// 查询标准参数
export function listStandardParam(standardId) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      data: mockData.standardParams
    });
  }
  
  return request({
    url: '/qep/standard/param/list',
    method: 'get',
    params: { standardId: standardId }
  })
} 